package com.forezp.datastruct;

/**
 * 用数组实现的map
 * Created by forezp on 2017/12/7.
 */
public class ArrayMap<K, V> {
    private final int defaultCapcity = 16;
    Object[][] pairs;
    int capcity;
    int size;
    int modeCount;

    public ArrayMap() {
        pairs = new Object[defaultCapcity][2];
        capcity = defaultCapcity;
    }

    public ArrayMap(int capcity) {
        this.capcity = capcity;
        pairs = new Object[capcity][2];
    }

    public void put(K key, V value) {
        pairs[size][0] = key;
        pairs[size][1] = value;
        size++;
    }

    public V get(K key) {

        for (int i = 0; i < size; i++) {
            if (pairs[i][0].equals(key)) {
                return (V) pairs[i][1];
            }
        }
        return null;

    }


}
